package com.google.code.main;

import java.util.List;

import org.dom4j.DocumentException;
import org.tanukisoftware.wrapper.WrapperListener;
import org.tanukisoftware.wrapper.WrapperManager;

import com.google.code.robot.HeroConf;
import com.google.code.robot.Player;
import com.google.code.robot.Robot;

public class WrapperMain extends Thread implements WrapperListener {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("Initializing...");
		WrapperManager.start(new WrapperMain(), args);
	}

	@Override
	public void controlEvent(int arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public Integer start(String[] arg0) {
		// TODO Auto-generated method stub
		System.out.println(">>> start");
		this.start();
		System.out.println("<<< start");
		return null;
	}

	@Override
	public int stop(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public void run() {
		HeroConf conf = HeroConf.getInstance();
		List<Player> players = null;
		try {
			players = conf.getPlyaers();
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		for (Player player : players) {
			new Robot(player).start();
		}
	}
}
